// JavaScript Document
function textareaMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}
function trim(s) {
	return rtrim(ltrim(s));
}

function ltrim(s) {
	var l = 0;
	while (l < s.length && s[l] == ' ') {
		l++;
	}
	return s.substring(l, s.length);
}

function rtrim(s) {
	var r = s.length - 1;
	while (r > 0 && s[r] == ' ') {
		r -= 1;
	}
	return s.substring(0, r + 1);
}
function Right(str, n){
if (n <= 0)
return "";
else if (n > String(str).length)
return str;
else {
var iLen = String(str).length;
return String(str).substring(iLen, iLen - n);
}
}
function Formvalidate(Form) {
	var forms = document.getElementById(Form);
	for ( var i = 0; i < forms.length; i++) {
		var typetemp = forms[i].type;
		if(typetemp!="radio" && typetemp!="hidden"){
			var temp = forms[i].id;		
			if (trim(document.getElementById(temp).value) == "") {
			
				if(Right(temp,3)=="_DT"){
					alert("日付を選択してください。");
					return false;
				}
				if (temp.substring(0, 2) == "PK") {
					document.getElementById(temp).style.background = "#F00";
					//document.getElementById(temp).focus();
					return false;
				}
			}
		}
		

	}
	return true;
	// document.forms[forms].onsubmit;
	
}
function infocustext(Element){
	//alert("Please select something");
	document.getElementById(Element).style.background= "#FFFF00";
}
function outfocustext(Element){
	if(Right(Element,4)=="_NUM"){
		if(isNumber(Element)){
			document.getElementById(Element).style.background= "#FFFFFF";
		}
	}else{
		document.getElementById(Element).style.background= "#FFFFFF";
	}
	
}
function FormLoad(Form){
//	alert("k");
	var forms = document.getElementById(Form);
	for ( var i = 0; i < forms.length; i++) {
		var temp = forms[i].type;

		if(temp	=="text"){	
			
			forms[i].setAttribute("onfocus","infocustext('"+forms[i].id+"')");
			forms[i].setAttribute("onblur","outfocustext('"+forms[i].id+"')");
		}
		
	}
	
}
function validatedate(objyear, objmoth, objday) {
	// alert("Please select something");
	var Year = document.getElementById(objyear).value;
	var moth = document.getElementById(objmoth).value;
	var day = document.getElementById(objday).value;
	option = document.createElement("option");
	var combo = document.getElementById(objday);
	var moth31day = new Array(1, 3, 5, 7, 8, 10, 12);
	var i = 0;
	for (i; i < 7; i++) {
		if (moth == moth31day[i]) {
			if (combo.length == 29) {
				option.text = "29";
				option.value = "29";
				combo.add(option);
				validatedate(objyear, objmoth, objday);
			}

			if (combo.length == 30) {
				option.text = "30";
				option.value = "30";
				combo.add(option);
				validatedate(objyear, objmoth, objday);
			}
			if (combo.length == 31) {
				// alert("vui long kiem tra lai date");
				option.text = "31";
				option.value = "31";
				combo.add(option);
				validatedate(objyear, objmoth, objday);
			}
			return true;
		}
	}
	if (combo.length == 29) {
		option.text = "29";
		option.value = "29";
		combo.add(option);
		validatedate(objyear, objmoth, objday);
	}
	if (combo.length == 30) {
		option.text = "30";
		option.value = "30";
		combo.add(option);
		validatedate(objyear, objmoth, objday);
	}
	if (combo.length == 31) {
		option.text = "31";
		option.value = "31";
		combo.add(option);
		validatedate(objyear, objmoth, objday);
	}
	combo.remove(31);
	if (moth == 2) {
		if ((Year % 4 == 0) || ((Year % 400 == 0) && (Year % 100 != 0))) {
			if (combo.length <= 28) {
				option.text = "29";
				option.value = "29";
				combo.add(option);
			} else {
				combo.remove(30);
			}

		} else {
			combo.remove(30);
			combo.remove(29);
		}

	}
	return true;
}
function Dateshow(datevalue) {

}
function inputNumber(e) {
	var keypressed = null;
	if (window.event) {
		keypressed = window.event.keyCode; // IE
	} else {
		keypressed = e.which; // NON-IE, Standard
	}

	if (keypressed < 48 || keypressed > 57) {

		if (keypressed == 8 || keypressed == 127 || keypressed == 13) {// Phím
																		// Delete
																		// và
																		// Phím
																		// Back
			return;
		}
		alert("数字を入力してください。");
		return false;
	}
}
function isNumber(value) {
	// alert("Please input type number");
	var temp = document.getElementById(value).value;
	// alert(temp);
	if (isNaN(temp)) {
		alert("数字を入力してください。");
		document.getElementById(value).focus();
		return false;
	}
	return true;
}